<template>
  <div class="goods-info-container" v-loading.lock.lock="fullscreenLoading">
    <!-- 商品库存数量、商品已售数量、商品是否库存紧张 -->
    <div class="goods-num-info">商品数量</div>
    <!-- 商品信息表 -->
    <div class="goods-info-table">商品信息表</div>
    <!-- 商品数据可视化图形 -->
    <div class="goods-visualization" ref="chartDom">商品可视化</div>
  </div>
</template>

<script setup>
import { ElMessage } from 'element-plus'
import { ref, reactive, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import * as echarts from 'echarts'
import axios from '@/utils/request'

// 创建路由对象
const route = useRoute()
const router = useRouter()
const chartDom = ref(null)
const id = route.params.id
const goodsData = reactive({})
let fullscreenLoading = ref(false)
let option = reactive({
  title: {
    text: 'Stacked Area Chart'
  },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross',
      label: {
        backgroundColor: '#6a7985'
      }
    }
  },
  legend: {
    data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
  },
  toolbox: {
    feature: {
      saveAsImage: {}
    }
  },
  grid: {
    left: '3%',
    right: '4%',
    bottom: '3%',
    containLabel: true
  },
  xAxis: [
    {
      type: 'category',
      boundaryGap: false,
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    }
  ],
  yAxis: [
    {
      type: 'value'
    }
  ],
  series: [
    {
      name: 'Email',
      type: 'line',
      stack: 'Total',
      areaStyle: {},
      emphasis: {
        focus: 'series'
      },
      data: [120, 132, 101, 134, 90, 230, 210]
    },
    {
      name: 'Union Ads',
      type: 'line',
      stack: 'Total',
      areaStyle: {},
      emphasis: {
        focus: 'series'
      },
      data: [220, 182, 191, 234, 290, 330, 310]
    },
    {
      name: 'Video Ads',
      type: 'line',
      stack: 'Total',
      areaStyle: {},
      emphasis: {
        focus: 'series'
      },
      data: [150, 232, 201, 154, 190, 330, 410]
    },
    {
      name: 'Direct',
      type: 'line',
      stack: 'Total',
      areaStyle: {},
      emphasis: {
        focus: 'series'
      },
      data: [320, 332, 301, 334, 390, 330, 320]
    },
    {
      name: 'Search Engine',
      type: 'line',
      stack: 'Total',
      label: {
        show: true,
        position: 'top'
      },
      areaStyle: {},
      emphasis: {
        focus: 'series'
      },
      data: [820, 932, 901, 934, 1290, 1330, 1320]
    }
  ]
})

// 创建图标
const createImageTable = () => {
  var myChart = echarts.init(chartDom)
  option && myChart.setOption(option)
}
// 获取商品信息
const getGoodsInfo = async () => {
  fullscreenLoading.value = true
  try {
  } catch {
    ElMessage.error('请求失败！')
  } finally {
    fullscreenLoading.value = false
  }
  const data = await axios.get('/bus/goods/' + id)
  console.log(data)
  if (data.code === 0) {
    // 获取商品信息成功
    ElMessage({
      type: 'success',
      message: data.msg
    })
  } else if (data.code === 403 || data.msg === '身份验证失败') {
    ElMessage({
      type: 'error',
      message: data.msg
    })
    localStorage.removeItem('bus_token')
    router.replace('/login')
  } else {
    ElMessage({
      type: 'error',
      message: data.msg
    })
  }
}
onMounted(() => {
  // createImageTable()
})
getGoodsInfo()
</script>

<style lang="scss" scoped>
.goods-info-container {
  padding: 50px;

  .goods-num-info {
    border: 1px solid #e1e1e1;
  }
  .goods-info-table {
    border: 1px solid #e1e1e1;
    margin-top: 30px;
  }
  .goods-visualization {
    border: 1px solid #e1e1e1;
    margin-top: 30px;
    height: 500px;
  }
}
</style>
